import 'package:flutter/material.dart';
import 'package:flutter_boost/flutter_boost.dart';

class FirstPageWidget extends StatefulWidget {
  final Map params;
  FirstPageWidget(this.params);

  @override
  _FirstPageWidgetState createState() => _FirstPageWidgetState(params);
}

class _FirstPageWidgetState extends State<FirstPageWidget> {
  final Map params;
  _FirstPageWidgetState(this.params);

  String value = '';

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        children: <Widget>[
          Text("我是FirstPage，参数是：$params"),
          ElevatedButton(
            child: Text('与原生push一样的页面'),
            onPressed: () {
              //dart通过原生跳转dart页面
              BoostNavigator.instance.push("firstPage",arguments: {"key": "我跳了一个页面","isAnimated":"1"},withContainer: true);
            },
          ),
          ElevatedButton(
            child: Text('Go back!'),
            onPressed: () {
              //关闭dart页面
              BoostNavigator.instance.pop();
            },
          ),
          ElevatedButton(
              child: Text('Flutter call Native'), onPressed: _flutterCallNative),
          Text(value.length > 0 ? "收到消息：$value" : '')
        ],
      ),
    );
  }

  _flutterCallNative() {
    BoostChannel.instance.sendEventToNative("flutter_to_native", {"key":"我是参数"});
  }
}
